<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<% String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
    <title>客户开发计划管理</title>
    <base href=<%=basePath%>
          <%@include file="../common_css.jsp"%>
                  </head>
<body class="childrenBody">
<form class="layui-form" >
    <blockquote class="layui-elem-quote quoteBox">
        <form class="layui-form">
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input type="text" name="customerName"
                           class="layui-input
					searchVal" placeholder="客户名" />
                </div>
                <div class="layui-input-inline">
                    <select name="userId"  id="userId">
                        <option value="-1" >全部员工</option>
                    </select>
                </div>
                <a class="layui-btn search_btn" data-type="reload"><i
                        class="layui-icon">&#xe615;</i> 搜索</a>
            </div>
        </form>
    </blockquote>
    <table id="saleChanceList" class="layui-table"  lay-filter="saleChances"></table>


    <script type="text/html" id="toolbarDemo">
	</script>

    <!--操作-->
    <script id="op" type="text/html" >
        <a href="javascript:;"  class="layui-btn layui-btn-warm layui-btn-xs"  lay-event="edit">编辑</a>
        <a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-xs"  lay-event="info">详情</a>
    </script>

</form>
<script type="text/javascript">
    layui.use(['table','layer'],function(){
        var layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            table = layui.table;
        //机会数据列表展示
        var  tableIns = table.render({
            elem: '#saleChanceList',
            url : '/customer/list',
            cellMinWidth : 95,
            page : true,
            height : "full-125",
            limits : [10,15,20,25],
            limit : 10,
            toolbar: "#toolbarDemo",
            id : "saleChanceListTable",
            cols : [[
                {field: "id", title:'编号',fixed:"true",width:80},
                {field: 'name', title: '客户姓名',align:"center"},
                {field: 'phone', title: '手机号',  align:'center'},
                {field: 'weixin', title: '客户微信',  align:'center'},
                {field: 'userName', title: '员工姓名', align:'center',templet: function (d) {
                        return d.user.name;
                    }},
                {field: 'overview', title: '客户渠道', align:'center',templet: function (d) {
                        return d.activity.place;
                    }},
                {field: 'customerState', title: '客户状态', align:'center',templet: function (d) {
                        return d.stringCustomerState;
                    }},
                {field: 'createTime', title: '创建时间', align:'center'},
                {title: '操作',fixed:"right",align:"center", minWidth:150,templet:"#op"}
            ]]
        });
        $.post("/user/findUser",function (res) {
            for(var i=0;i<res.length;i++){
                //绑定下拉框显示
                $("#userId").append("<option value=\""+res[i].id+"\"   >"+res[i].name+"</option>");
            }
            // 重新渲染下拉框内容
            layui.form.render("select");
        });
        $(".search_btn").on("click",function () {
            table.reload("saleChanceListTable",{
                page:{
                    curr:1
                },
                where:{
                    customerName:$("input[name='customerName']").val(),// 客户名
                    userId:$("#userId").val(),// 客户名
                },
                url : "/customer/condition",
                method : "post",
                contentType :"application/json"
            })
        });

        //打开子窗口
        table.on("tool(saleChances)",function (obj) {
            var layEvent = obj.event;
            if(layEvent=='edit'){
                layui.layer.open({
                    title:'客户详细信息',
                    type:2,
                    area:["600px","400px"],
                    maxmin:true,
                    content:'customer/toCustomerPage?id='+obj.data.id
                })
            }else {
                layui.layer.open({
                    title:'计划项数据详情',
                    type:2,
                    area:["800px","550px"],
                    maxmin:true,
                    content:"/cusDevelop/toCusDevData?id="+obj.data.id
                })
            }
        });

    });
</script>

</body>
</html>